package ca.qc.bdeb.info.pp2.tp2.controleur;

import ca.qc.bdeb.info.pp2.tp2.application.AgentBean;
import ca.qc.bdeb.info.pp2.tp2.application.Facade;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

public class CommandeRechercherAgent implements Commande
{
    private String next;

    public CommandeRechercherAgent(String next)
    {
        this.next = next.toLowerCase();
    }

    @Override
    public String executer(HttpServletRequest req) throws CommandeException
    {
        Facade f = new Facade();

        String prenom = req.getParameter(ConstantesWeb.VALEUR_PRENOM);
        String nom = req.getParameter(ConstantesWeb.VALEUR_NOM);
        String codePostal = req.getParameter(ConstantesWeb.VALEUR_CODE_POSTAL);

        List<AgentBean> agent = f.getAgent(prenom, nom, codePostal);

        req.setAttribute(ConstantesWeb.VALEURS_LISTE_AGENTS, agent);
        return next;
    }
}
